<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>发布文章|<{$configcache['Title']}></title>
    <link rel="stylesheet" type="text/css" href="__CSS__/content.css"  />
    <link rel="stylesheet" type="text/css" href="__CSS__/public.css"  />
    <link rel="stylesheet" type="text/css" href="__ROOT__/dist/css/wangEditor.min.css">
    <script type="text/javascript" src="__JS__/jquery.js"></script>
    <script type="text/javascript" src="__JS__/Public.js"></script>
    <script type="text/javascript" src="__JS__/winpop.js"></script>
    <script type="text/javascript" src="__JS__/check.js"></script>
    <script type="text/javascript" src="__JS__/jquery-form.js"></script>
    <link rel="stylesheet" href="__JS__/Validform/images/style.css" type="text/css" media="all" />
    <script type="text/javascript" src="__JS__/Validform/images/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="__JS__/Validform/images/Validform_v5.3.2.js"></script>
    <script type="text/javascript" src="__JS__/Validform/plugin/passwordStrength/passwordStrength-min.js"></script>
    <script src="__JS__/jquery-form.js" type="text/javascript"></script>
    <script type="text/javascript" src="__JS__/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="__ROOT__/dist/js/wangEditor.js"></script>
    <!--<script type="text/javascript" src="__ROOT__/ueditor/ueditor.config.js"></script>-->
    <!--<script type="text/javascript" src="__ROOT__/ueditor/ueditor.all.min.js"> </script>-->
    <!--<script type="text/javascript" src="__ROOT__/ueditor/lang/zh-cn/zh-cn.js"></script>-->

    <script type="text/javascript" src="__JS__/PCASClass.js"></script>
    <script type="text/javascript" src="__JS__/layer/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="__JS__/layer/skin/layer.css" />
    <style type="text/css">
    #content .collect { width:auto; height:30px; border:none; padding:0px 18px; background:#f60; color:#fff; font-size:14px; font-family:"微软雅黑"; text-align:center; cursor:pointer; margin-left:30px; text-indent:0; }
    #content .collect:hover { background:#f90; }
   
      .dd_left{margin-top: 5px;}
        .dtext{text-align: center;}
        #preview, .img, img{width:200px;height:200px;}
        #view{} .imgbox{float:left;position:relative;width:100px;height: 100px;margin-left: 10px;margin-top: 10px;
          padding:5px;border:solid 1px #ccc;border-radius: 5px;;}
        #view{} .imgbox .close{border: solid 1px #ccc;position: absolute;top: -15px;
              width: 20px;height: 20px; display: inherit;cursor: pointer;text-align: center;background: red;color: #fff;right: -10px;z-index: 20;border-radius: 100%;}
        #view{} .imgbox input{width:100%;height: 100%;z-index: 10;}
        .tablecon{width: 800px; margin-left:80px;}
   </style>
	
	
	 
    <script type="text/javascript">
    $(function(){
        $(".registerform").Validform({
            tiptype:2,
            /*表单验证*/
            tiptype:function(msg,o,cssctl){
                if(!o.obj.is("form")){
                    var objtip=o.obj.parent().find(".Validform_checktip");
                    cssctl(objtip,o.type);
                    objtip.text(msg);

                    var infoObj=o.obj.parent().find(".info");
                    if(o.type==2){
                        infoObj.fadeOut(200);
                    }else{
                        layer.closeAll('loading');
                        if(infoObj.is(":visible")){return;}
                        infoObj.css({
                            left:0,
                            top:-30
                        }).show().animate({
                            top:-27
                        },200);
                    }
                }
            },
        });
    })
    </script>
</head>
<body>
    <div id="content">
        <h1>首页 > 学院管理 > 发布文章</h1>
        <h2>
            <div class="h2_left">
                <a href="__ACTION__" class="whole">全部</a>
                <a href="javascript:;" class="f5" onclick="f5();">刷新</a>
                <a href="javascript:;" onclick="location.href='__APP__/College/article'" class="uclass">列表</a>
                <a href="javascript:history.back();" class="Retreat">后退</a>
                <a href="javascript:history.go(1);" class="Advance">前进</a>
            </div>
        </h2>
     
           <form action="<{$SMART_URL}>/smart/article/manager/save" method="post" enctype="multipart/form-data" class="registerform" id="form">
            <dl id="cdl">
               <dd>
                <span class="dd_left">标题：</span>
                <span class="dd_right">
                   <input type="text" class="qtext title" name="articleName" datatype="*2-80" errormsg="标题名称在2~80位之间！"  nullmsg="请填写标题名称！" maxlength=80 /><font class="defi defi-01"><span class="Validform_checktip"></span></font>
               </span>
           </dd>
          
		    <dl id="cdl">
               <dd>
                <span class="dd_left">文章来源：</span>
                <span class="dd_right">
				   <select  class="select"  name="articleSource" >
					  <option selected value="原创文章">原创文章</option>
					  <!--默认选中-->
					  <option  value="转发文章">转发文章</option>
					
					</select>
					
               </span>
           </dd>
		    <input type="hidden" class="qtext" name="userRole" value="2" id="userRole" />
                 <input type="hidden" class="qtext" name="userName" value="管理员" id="userName" />
		   
		      <dl id="cdl">
               <dd>
                <span class="dd_left">类目：</span>
                <span class="dd_right">
				   <select id="s1" class="select" name="mainCode" onChange="move()">
					<!-- 根据id获取value，onchange（）触发函数move（）修改二级select的text值实现联动 -->
					  <option selected value="s1"  >-- 请选择 --</option>
					  <!--默认选中-->
					  <option  value="100">软件开发</option>
					  <option   value="200">硬件开发</option>
					  <option   value="300">UED&运营</option>
					  <option   value="400">精品文章</option>
					</select>
					<select   class="select" name="subCode" id="s2">
					   <option selected>-- 请选择 --</option>
					   <!--默认选中，动态生成option -->
					</select>
               </span>
           </dd>
		   <dd>
                    <div id="reader_box"></div>
                    <span class="dd_right" id="str">
                    </span>
                </dd>
		  <dd>
                    <div id="reader_box"></div>
                    <span class="dd_left">上传图片:</span>
                    <span class="dd_right">
                        <input type="file" name="file" id="file" onchange="load(this)" class='myfile'></input>
                        <div id="view"></div>
                        <div id="imgkey"></div>
                    </span>
                </dd>

          <dd>
            <span class="dd_left">文章简介：</span>
            <span class="dd_right"><!--用父容器来控制宽度-->

                <textarea class="textarea" name="articleIntro" style="height:100px;max-height:200px;"></textarea>
                
            </span>
        </dd>

        <dd>
            <span class="dd_left">内容：</span>
            <span class="dd_right"><!--用父容器来控制宽度-->

                <textarea id="textarea" name="articleContent" style="height:400px;max-height:500px;">
                </textarea>
                <!--<div id="content"></div>-->
            </span>
        </dd>
        <dd><input type="submit" name="submit" value="提交" class="submit" /></dd>
    </dl>
    <input type="hidden" name="" value="<{:U('College/article')}>" id="jump">
 </form>
</div>

<script>
  
$.ajaxSetup({ 
    async : false 
});  
 function getDataByPost(parentCode)
    {
    	var array;
		  $.post("http://139.196.194.93:8080/smart/home/queyNav",
		  {
		    parentCode:parentCode,
		  },function(data,status){
		  	
		  		 array=  data.data.navList;
		  });
        return  array;
    }


   function move()
     {
         var s1=document.getElementById("s1");
         var s2=document.getElementById("s2");
         <!-- 获取一级和二级的属性-->
         var add;
         if(s1.value=="100")
         {
            /* add=new Array("IOS应用开发","Android应用开发","WEB前端开发","Python WEB开发","php开发","软件测试","自动化运维+云计算","网络安全");*/
  
            add=getDataByPost(100);

             <!--比对value值，实现对应二级text值的动态生成-->
         }else if(s1.value=="200")
         {
          /*   add=new Array("嵌入式系统开发","物联网开发");*/
      
      		 add=getDataByPost(200);

             <!--比对value值，实现对应二级text值的动态生成-->
         }else if(s1.value=="300")
         {
             /*add=new Array("产品经理","新媒体网络运营","UI设计","平面设计");*/
              add=getDataByPost(300);
             <!--比对value值，实现对应二级text值的动态生成-->
           }else if(s1.value=="400")
         {
             /*add=new Array("大咖心得","就业指导","技术干货","行业资讯");*/
             add=getDataByPost(400);
             <!--比对value值，实现对应二级text值的动态生成-->
           }else if(s1.value=="s1")
          {
              add=new Array("请选择");
            }
          else
          {
         add=null;
         <!--若没有就为空，当然不可能出现的-->
          }

          s2.length=0;
          for(var i=0;i<add.length;i++)
          {
              var ss=new Option();
              ss.text=(add[i].text).split()[0];

              s2.add(ss);
              <!--把text值添加到二级select中，显示出来-->
          }

     }



var editor = new wangEditor('textarea');
    // 上传图片
    editor.config.uploadImgUrl = 'http://139.196.194.93:8080/smart/image/upload';
    // 自定义上传事件
    editor.config.uploadImgFns.onload = function (resultText, xhr) {
        // resultText 服务器端返回的text
        // xhr 是 xmlHttpRequest 对象，IE8、9中不支持
        // 上传图片时，已经将图片的名字存在 editor.uploadImgOriginalName
        var originalName = editor.uploadImgOriginalName || '';
//	    var url = jQuery.parseJSON(resultText).keyUrl
        // 如果 resultText 是图片的url地址，可以这样插入图片：
        editor.command(null, 'insertHtml', '<img src="' + resultText + '" alt="' + originalName + '" style="max-width:100%;"/>');
        // 如果不想要 img 的 max-width 样式，也可以这样插入：
        // editor.command(null, 'InsertImage', resultText);
    };
    editor.create();
    $('#btn1').click(function () {
        // 获取编辑器区域完整html代码
        var html = editor.$txt.html();
//        var content = document.getElementById('content');
//        content.innerHTML = '<input type="hidden" name="mainPicKey" value="' + html + '"/>';
});

    $(function(){
        $(document).ready(function(){
            $('#form').ajaxForm(function(data){
                var index = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });

                if(data.code =="2000" ){
                    layer.closeAll('loading');
                    alert(data.message);
                    var url = $('#jump').val();
                    window.location.href = url;
                    //console.log(data)
                }else{
                    layer.closeAll('loading');
                    alert(data.message);
                    //console.log(data);
                }
            });
        });
    });
	
	
	
	
	var imgkey = [];
function load(file) {
    var num=1;
    $('.imgbox').remove();
    if (file.files) {
        for (var i = 0; i < file.files.length; i++) {
            var reader = new FileReader();
            reader.readAsDataURL(file.files[i]);
            reader.onload = function(evt) {
                var imgbox=$('<div></div>');
                imgbox.addClass('imgbox');
                $('#view').append(imgbox);
                var imgs = $('<input type="image" />');
                imgs.attr('name','mum'+num);
                num++;
                imgs.appendTo(imgbox);
                imgs.attr('src', evt.target.result);
            }
        }
    }
}

$(function(){
    $(document).ready(function(){
        $('.submit').click(function(){
            var index = layer.load(1, {shade: [0.1,'#fff']});
        });

        $('#form').ajaxForm(function(data){
        //弹出ajax请求后的回调结果，data回调数据  onclick="sub()"
        if(data.code =="2000" ){ 
            layer.closeAll('loading');
            alert(data.message);
            var url = $('#jump').val();
            window.location.href = url; 
            // location.href=document.referrer; 
        }else{
            layer.closeAll('loading');
            alert(data.message);
        }
    });
    });
});


    $(document).on("change", "input[name=file]", logosub);
    function logosub() {
        //模拟form表单提交数据
        var filepath=$("input[name='file']").val();
        var extStart=filepath.lastIndexOf("."); 
        var ext=filepath.substring(extStart,filepath.length).toUpperCase(); 
        if(ext!=".jpeg"&&ext!=".jpg"&&ext!=".bmp"&&ext!=".png" &&ext!=".JPEG"&&ext!=".JPG"&&ext!=".BMP"&&ext!=".PNG"){ 
            alert("文件选择错误,图片类型必须是jpeg,jpg,bmp,png中的一种"); 
            return false; 
        }

        var index = layer.load(1, {shade: [0.1,'#fff']});
        var fileObj = document.getElementById("file").files[0];
        var FileController = '<{$SMART_URL}>/smart/image/uploadImg';
        var form = new FormData();
        form.append("imgFile", fileObj);
        var xhr = new XMLHttpRequest();
        xhr.open("post", FileController, true);
        xhr.onload = function (json) {
            var obj = jQuery.parseJSON(json.target.responseText);
            console.log(obj);
            layer.closeAll('loading');
           
                // console.log(obj.data.key);return;
                var html = '<input type="hidden" name="mainArticlePic" value="'+obj.key+'">';
                $('#imgkey').html(html);


                alert("上传图片成功");
            
        };
        xhr.send(form);
    }

    </script>
</body>
</html>
